home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume90
/
aplictns
/
xscheme2
/
part01
/
pi-calc.s
< prev
next >
Wrap
Text File
|
1990-04-14
|
578b
|
29 lines
(define (pi-calc n)
(define (a n)
(if (zero? n)
1
(/ (+ (a (-1+ n))
(b (-1+ n)))
2)))
(define (b n)
(if (zero? n)
(/ (sqrt 2))
(sqrt (* (a (-1+ n))
(b (-1+ n))))))
(define (square x)
(* x x))
(define (two2theN n)
(if (zero? n)
1
(* 2 (two2theN (-1+ n)))))
(define (sumof start end func)
(let ((first (func start)))
(if (= start end)
first
(+ first (sumof (1+ start) end func)))))
(define (denom-func i)
(* (two2theN i)
(square (- (a i) (b i)))))
(/ (* 4 (a n) (b n))
(- 1 (sumof 0 (-1+ n) denom-func))))